/**
 * editor_plugin_src.js
 *
 * Copyright 2009, Moxiecode Systems AB
 * Released under LGPL License.
 *
 * License: http://tinymce.moxiecode.com/license
 * Contributing: http://tinymce.moxiecode.com/contributing
 */

(function() {
    tinymce.create('tinymce.plugins.PopupLinkPlugin', {
        init : function(ed, url) {
            this.editor = ed;

            // Register commands
            ed.addCommand('mcePopupLink', function() {
                // Internal image object like a flash placeholder
                if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
                    return;

                ed.windowManager.open({
                    file : url + '/link.htm',
                    width : 500 + parseInt(ed.getLang('popuplink.delta_width', 0)),
                    height : 240 + parseInt(ed.getLang('popuplink.delta_height', 0)),
                    inline : 1
                }, {
                    plugin_url : url
                });
            });

            // Register buttons
            ed.addButton('popuplink', {
                title: 'popuplink.desc',
                cmd:   'mcePopupLink',
                image: url + '/img/icon.gif'
            });

            ed.onNodeChange.add(function(ed, cm, n, co) {
                var isActive = false;
                if (n.nodeName == "IMG")
                {
                    var parentNode = ed.dom.getParent(n, "A");
                    isActive = parentNode && parentNode.nodeName == "A"
                        && parentNode.className == this.getParam('popuplink_class');
                }
                cm.setActive('popuplink', isActive);
            });
        },

        getInfo : function() {
            return {
                longname : 'Popup link',
                author : 'iSpring Solutions, Ltd.',
                authorurl : 'http://ispringsolutions.com',
                infourl : '',
                version : tinymce.majorVersion + "." + tinymce.minorVersion
            };
        }
    });

    // Register plugin
    tinymce.PluginManager.add('popuplink', tinymce.plugins.PopupLinkPlugin);
})();